package org.example.lease.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.example.lease.model.entities.LabelInfo;
import org.example.lease.model.enums.ItemType;
import org.example.lease.model.result.Result;
import org.example.lease.service.LabelInfoService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 宋孟林
 * @description
 * @date: 2025/5/14 14:52
 */
@Tag(name = "标签管理")
@RestController
@Slf4j
@RequestMapping("/admin/label")
public class LabelController {
    @Resource
    private LabelInfoService labelInfoService;

    /**
     * 使用枚举类对象作为参数，参数不能为枚举类已经定义的枚举对象之外的对象,填写一个枚举对象
     * 请求地址：<code>/admin/label/list?itemType=ROOM</code>
     * @param itemType item
     * @return result
     */
    @Operation(summary = "（根据类型）查询标签列表")
    @GetMapping("/list")
    public Result<?> labelList(@RequestParam(required = false) ItemType itemType){
        List<LabelInfo> labelInfos = labelInfoService.labelList(itemType);
        return Result.ok(labelInfos);
    }

    @Operation(summary = "保存或者更新标签内容")
    @PostMapping("saveOrUpdate")
    public Result<?> saveOrUpdateFacility(@RequestParam LabelInfo labelInfo){
        labelInfoService.saveOrUpdate(labelInfo);
        return Result.ok();
    }

    @Operation(summary = "根据id删除标签")
    @PostMapping("/deleteById")
    public Result<?> deleteLabelById(@RequestParam Integer id){
        labelInfoService.removeById(id);
        return Result.ok();
    }
}
